#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QFile>
#include <QDataStream>
#include <iostream>
#include <QPixmap>
#include <QQuickWindow>
#include <QWindow>
#include <QQuickView>

#define UNICODE

#include <log4cplus/helpers/loglog.h>
#include <log4cplus/logger.h>
#include <log4cplus/initializer.h>

#include "constant.h"
#include "sniptools.h"

using namespace std;
using namespace log4cplus::helpers;

void printMsgs()
{
    cout << "Entering printMsgs()..." << endl;

    LogLog::getLogLog()->debug(LOG4CPLUS_TEXT("This is a Debug statement..."));
    LogLog::getLogLog()->debug(
        log4cplus::tstring(LOG4CPLUS_TEXT("This is a Debug statement...")));

    LogLog::getLogLog()->warn(LOG4CPLUS_TEXT("This is a Warning..."));
    LogLog::getLogLog()->warn(
        log4cplus::tstring(LOG4CPLUS_TEXT("This is a Warning...")));

    LogLog::getLogLog()->error(LOG4CPLUS_TEXT("This is a Error..."));
    LogLog::getLogLog()->error(
        log4cplus::tstring(LOG4CPLUS_TEXT("This is a Error...")));

    cout << "Exiting printMsgs()..." << endl << endl;
}

//void testGrab(QQuickWindow *widget)
//{
//    QImage fullScreen = SnipTools::grabFullScreen(widget);

//    fullScreen.save("F:/test/qt_fullscreen.png");
//}

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

    log4cplus::Initializer initializer;

    printMsgs();

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

//    for(auto obj : engine.rootObjects())
//    {
//        QQuickWindow* window = qobject_cast<QQuickWindow*>(obj);
//        if (window)
//        {
//            testGrab(window);
//        }
//    }

    return app.exec();
}
